package com.ky.tms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ky.tms.entity.TmsCarOil;
import com.ky.tms.mapper.TmsCarOilMapper;
import com.ky.tms.service.ITmsCarOilService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ky.tms.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chengkaimao
 * @since 2020-05-13
 */
@Service
public class TmsCarOilServiceImpl extends ServiceImpl<TmsCarOilMapper, TmsCarOil> implements ITmsCarOilService {

    @Override
    public IPage<TmsCarOil> oilPage(TmsCarOil tmsCarOil, Long limit, Long pages) {
        IPage<TmsCarOil> page = new Page(pages, limit);
        QueryWrapper<TmsCarOil> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(tmsCarOil.getOilNo())){
            wrapper.like("oil_no", tmsCarOil.getOilNo());
        }
        if(StringUtils.isNotEmpty(tmsCarOil.getCarNo())){
            wrapper.like("car_no", tmsCarOil.getCarNo());
        }
        if(StringUtils.isNotEmpty(tmsCarOil.getDriver())){
            wrapper.like("driver", tmsCarOil.getDriver());
        }

        if(tmsCarOil.getCreateTimeArray() != null && tmsCarOil.getCreateTimeArray().size()>0){
            wrapper.ge("oil_time", DateUtil.strToLocalTime(tmsCarOil.getCreateTimeArray().get(0),"yyyy-MM-dd HH:mm:ss"));
            wrapper.le("oil_time", DateUtil.strToLocalTime(tmsCarOil.getCreateTimeArray().get(1),"yyyy-MM-dd HH:mm:ss"));
        }
        wrapper.eq("is_valid", 1);
        wrapper.orderByDesc("create_time");
        page = this.page(page, wrapper);
        return page;
    }

}
